﻿/********************************************************************************
** @ Date:2024/12/30
** @ Author: Gaojia
** @ Description: vlc播放rtsp视频类
** @ Version:1.0.0
** @ Fun:
********************************************************************************/
#ifndef CVlcRtspOper_H
#define CVlcRtspOper_H
#include <QWidget>
#include <QMutex>
#include <QLabel>
#include <QTimer>
#include <QImage>
#include <qpointer.h>
#include "vlc/vlc.h"
#include "CDevDataCam.h"
class CVlcRtspOper : public QObject
{
	Q_OBJECT
public:
	CVlcRtspOper(CDevDataCam *pDevDataCam,const QString &url, QWidget *pWidget = nullptr);
	~CVlcRtspOper();
	bool init();
	bool initMainThread();   //在主线程初始化
	bool startCapture();
	bool stopCapture();
	void setRollerNum(int nNum, int nBologn, QString sRollerDesc);         //设置托辊号
	void setCorrectData(double dLeftRectifyValue, double dRightRectifyValue, int nRectifySetValue, int nRectifySetValueTwo, QPointF BeltEdgePf1, QPointF BeltEdgePf2, QPointF BeltEdgePf3, QPointF BeltEdgePf4,
		int nIsHaveBeltState, bool bBeltState, int nDrawType);
private:
	void drawRoller();
	void startThreadTask();
	void drawRollerRealign();
	QPen getPenForRectifyValue(double rectifyValue, double setValueTwo, double setValue, int m_nHaveBeltState);

private slots:
	void slot_CaptureFrame();
private:
	int m_nWidth;   //图片宽
	int m_nHeight;  //图片高
	int nLine;
	bool m_bInit;
	QThread *m_pThread;
	bool m_bThread;
	libvlc_instance_t *m_pVlcInstance;
	libvlc_media_player_t *m_pMediaPlayer;
	libvlc_media_t *m_pMedia;
	QPointer<QLabel> m_pImageLabel;
	QTimer *m_pFrameTimer;
	QImage *m_pCurrentFrame;
	QImage m_cDrawFrame;
	QString m_sUrl;
	CDevDataCam *m_pDevDataCam;
	int m_nDrawType;//0:机器人画托辊  1:跑偏画线及左下角显示纠偏值
	//机器人画托辊相关
	int m_nRollerNum;  //托辊号
	QString m_sRollerDesc;
	int m_nBelogn;    //AB侧托辊
	int m_nResizeIndex;  //界面刷新尺寸计数
	//跑偏画线和左下角文字相关
	QPointF m_BeltEdgePf1;//皮带边缘点1 左上
	QPointF m_BeltEdgePf2;//皮带边缘点2 右上
	QPointF m_BeltEdgePf3;//皮带边缘点3 右下
	QPointF m_BeltEdgePf4;//皮带边缘点4 左下
	double m_dLeftRectifyValue;//左偏值
	double m_dRightRectifyValue;//右偏值
	int m_nRectifySetValue;//一级跑偏判定值
	int m_nRectifySetValueTwo;//二级跑偏判定值
	int m_nIsHaveBeltState;//是否有皮带运行状态
	int m_bBeltState;//皮带运行状态
	bool m_bTimer;   //定时器状态
	QMutex m_cRollerLock;
	QMutex m_cImageLock;
private:
	// 自定义回调函数
	static void *lockCallback(void *opaque, void **planes);
	static void unlockCallback(void *opaque, void *picture, void *const *planes);
};

#endif